# coding=utf-8

print("\n*****************最基本的函数装饰器*****************\n")

def log(fun):
	def return_fun(*args, **kargs):
		print("开始输出日志")

		fun(*args, **kargs)

		print("结束输出日志")

	return return_fun

@log
def say(message):
	print(message)

say("段光伟")

print("\n*****************等价方法*****************\n")

def say(message):
	print(message)

say = log(say)
say("段光伟")



print("\n*****************带参数的函数装饰器*****************\n")

def log(header, footer):
	def log_to_return(fun):
		def return_fun(*args, **kargs):
			print(header)

			fun(*args, **kargs)

			print(footer)

		return return_fun
	return log_to_return

@log("开始输出日志", "结束输出日志")
def say(message):
	print(message)

say("段光伟")

print("\n*****************等价方法*****************\n")

def say(message):
	print(message)

say = log("开始输出日志", "结束输出日志")(say)
say("段光伟")



print("\n*****************最基本的类型装饰器*****************\n")
def flyable(cls):
	def fly(self):
		print("我要飞的更高")
	cls.fly = fly
	
	return cls

@flyable
class Man:
	pass

man = Man()
man.fly()

print("\n*****************等价方法*****************\n")

class Man:
	pass

Man = flyable(Man)

man = Man()
man.fly()



print("\n*****************带参数的类型装饰器*****************\n")
def flyable(message):
	def flyable_to_return(cls):
		def fly(self):
			print(message)
		cls.fly = fly
		
		return cls
	return flyable_to_return

@flyable("我要飞的更高")
class Man:
	pass

man = Man()
man.fly()

print("\n*****************等价方法*****************\n")

class Man:
	pass

Man = flyable("我要飞的更高")(Man)

man = Man()
man.fly()